package yl.hs.bmipfull.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Component;
import yl.hs.bmipfull.service.system.IUserService;
import yl.hs.bmipfull.utils.HsApp;

@Component(value = "AC")
public class AccessAuthentication {

    @Autowired
    IUserService userSvc;

    public boolean hasPermission() {
        var request = HsApp.getRequest();
        String url = request.getRequestURI();
        var authentication = TokenUtils.getAuthenticationFromToken(request);
        var authorities = authentication.getAuthorities();
        var flag = false;
        var iterator = authorities.iterator();
        while (iterator.hasNext()) {
            GrantedAuthority ac = iterator.next();
            if (url.equals(ac.getAuthority())) {
                flag = true;
            }
        }


        return flag;
    }
}
